//
//  ParentsViewController.m
//  IM_LearningGYDF
//
//  Created by gydf on 16/3/9.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ParentsViewController.h"

@interface ParentsViewController ()

@end

@implementation ParentsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self myAppInit];
    self.view.backgroundColor=[UIColor whiteColor];
    // Do any additional setup after loading the view.
   
}
-(UIActivityIndicatorView *)centerIndicator{
    if (!_centerIndicator) {
        _centerIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        _centerIndicator.center = self.view.center;
//        [self.view addSubview:_centerIndicator];
    }
    return _centerIndicator;
}
- (void)dataInit{
    
}
//- (void)createLabelWithPoint:(CGPoint)point addToView:(UIView*)view{
//    _alertLabel = [UILabel new];
//    _alertLabel.text = @"暂时没有相关的数据!";
//    _alertLabel.numberOfLines = 0;
//    _alertLabel.textColor = [UIColor darkGrayColor];
//    _alertLabel.font = FONT_14;
//    CGRect labelRect = [_alertLabel textRectForBounds:CGRectMake(0, 0, MAXFLOAT, 30) limitedToNumberOfLines:0];
//    _alertLabel.frame = CGRectMake(point.x, point.y, labelRect.size.width, 30);
//    [view addSubview:_alertLabel];
//}
//初始化
- (void)myAppInit{
    _pageNum=@"0";
    self.automaticallyAdjustsScrollViewInsets=NO;
    
    [[UINavigationBar appearance]setBarTintColor: COLOR_MIDBLUE];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
    self.navigationController.navigationBar.translucent=NO;
//    [self.navigationController.navigationBar setBackgroundImage:[[UIImage imageNamed: @"titlebar_big"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forBarMetrics:UIBarMetricsDefault];97.196,248
//    [self.navigationController.navigationBar setBarTintColor:COLORSET(97, 196, 255)];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backClick)];
    
    //[self setLeftBackNavigation];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];

}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];

}

- (void)addTapGestureRecognizerWithView:(id)view{
    //避免手势混乱 所以先移除
    if (_tapGesture) {
        [view removeGestureRecognizer:_tapGesture];
        _tapGesture=nil;
    }
    _tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureClick)];
    [view addGestureRecognizer:_tapGesture];
}

- (void)removeTapGestureRecognizerWithView:(id)view{
    [view removeGestureRecognizer:_tapGesture];
    _tapGesture=nil;
}
#pragma mark -手势的响应事件
- (void)tapGestureClick{
    [self.view endEditing:YES];
}

#pragma mark -获取当前时间请求

- (void)serverDateRequest{
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content></content>",[LZXHelper getSessionID]];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getServiceTime soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"200"]) {
            NSDictionary *dataDict=responseObject[@"retContent"];
            self.serviceTime=[dataDict[@"serviceTime"] copy];
            
        }else if([model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}
//设置左边导航栏
- (void)setLeftBackNavigation{  
    UIBarButtonItem *item=[[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"icon1_1@2x"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backClick)];

    self.navigationItem.leftBarButtonItem=item;
}
//隐藏左边导航栏
-(void)setLeftBackHidden{
    self.navigationItem.leftBarButtonItem = nil;
}
//返回上一页
- (void)backClick{
    [self.navigationController popViewControllerAnimated:YES];
}


//右边导航栏
- (void)setRightNavigation:(NSString *)title{
    //
    if (self.navigationItem.rightBarButtonItem) {
        self.navigationItem.rightBarButtonItem.title=title;
    }else{
        UIBarButtonItem *item=[[UIBarButtonItem alloc]initWithTitle:title style:UIBarButtonItemStylePlain target:self action:@selector(rightItemClick:)];
        [item setTintColor:[UIColor whiteColor]];
        self.navigationItem.rightBarButtonItem=item;
    }

//    [self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:13], NSFontAttributeName, [UIColor whiteColor], NSFontAttributeName, nil] forState:UIControlStateNormal];
}

//设置右侧导航栏
- (void)setRightBackNavigation{
    UIBarButtonItem *item=[[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"k_axis_nor@2x"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(rightItemClick:)];
    [item setTintColor:[UIColor whiteColor]];
    self.navigationItem.rightBarButtonItem=item;
}


- (void)rightItemClick:(UIBarButtonItem *)item{
    [self.navigationController popToRootViewControllerAnimated:YES];
}


- (void)setNavigationTitle:(NSString *)title
{
    if ([self.navigationItem.titleView isKindOfClass:[UILabel class]]) {
        [(UILabel *)self.navigationItem.titleView setText:title];
        [(UILabel *)self.navigationItem.titleView sizeToFit];
    }
    else {
        UILabel *label = [[UILabel alloc] init];
        label.backgroundColor = [UIColor clearColor];
        [label setText:title];
        [label setTextColor:[UIColor whiteColor]];
        [label setFont:[UIFont systemFontOfSize:18]];
        label.textAlignment = NSTextAlignmentCenter;
        label.numberOfLines = 0;
        [label sizeToFit];
        self.navigationItem.titleView = label;
    }
}

//暂时没用
//- (void)postWithURLAPI:(NSString *)API parameters:(id)parameters success:(void (^)(id, NSString *))success failure:(void (^)(NSError *, NSString *))failure{
//    [HttpRequest postWithURLString:[NSString stringWithFormat:@"%@%@",URL_TEST,API] parameters:parameters success:^(id responseObject) {
//        if (success) {
//            success(responseObject,API);
//        }
//    } failure:^(NSError *error) {
//        if (failure) {
//            failure(error,API);
//        };
//    }];
//
//}
//
//- (void)getWithURLAPI:(NSString *)API success:(void (^)(id, NSString *))success failure:(void (^)(NSError *, NSString *))failure{
//    [HttpRequest getWithURLString:[NSString stringWithFormat:@"%@%@",URL_TEST,API] parameters:nil success:^(id responseObject) {
//        if (success) {
//            success(responseObject,API);
//        }
//    } failure:^(NSError *error) {
//        if (failure) {
//            failure(error,API);
//        };
//    }];
//}
//- (void)requestSuccessWithResponse:(id)response bindingIdentity:(NSString *)bindingIdentity{
//    
//}
//下刷新数据
- (void)addTableViewUpdateRefresh:(UITableView *)tableView BindingIdentity:(NSString *)BindingIdentity
{
    __weak typeof(self) weakSelf=self;
    tableView.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
        if (weakSelf.isLoadMore==NO&&weakSelf.isRefresh==NO) {
            [weakSelf loadUpdateRefreshWithBindingIdentity:BindingIdentity];
        }
    }];
    
}
//上拉加载更多
- (void)addTableViewLoadMoreData:(UITableView *)tableView BindingIdentity:(NSString *)BindingIdentity
{
    __weak typeof(self) weakSelf=self;
    tableView.mj_footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        if (weakSelf.isRefresh==NO&&weakSelf.isLoadMore==NO) {
            [weakSelf loadMoreDataWithBindingIdentity:BindingIdentity];
        }
    }];
}

- (void)loadMoreDataWithBindingIdentity:(NSString *)BindingIdentity
{
    NSLog(@"子类需要重写");
}

- (void)loadUpdateRefreshWithBindingIdentity:(NSString *)BindingIdentity
{
    NSLog(@"子类需要重写");
}

- (void)endRefreshWithTableView:(UITableView *)tableView{
    [tableView.mj_header endRefreshing];
    [tableView.mj_footer endRefreshing];
    _isLoadMore=NO;
    _isRefresh=NO;
}

- (void)noMoreDataWithTableView:(UITableView *)tableView{
    [tableView.mj_footer endRefreshingWithNoMoreData];
}

- (void)hideMjRefreshFooterViewWithTableView:(UITableView *)tableView isHide:(BOOL)isHide{
    tableView.mj_footer.hidden=isHide;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc{
    NSLog(@"viewControllerDealloc");
}

- (void)addReminderViewWithFrame:(CGRect)frame msg:(NSString *)msg backView:(UIView *)view{
    UIView *backView=(UIView*)[self.view viewWithTag:299];
    if (backView) {
        return;
    }
    backView=[[UIView alloc]initWithFrame:frame];
    backView.backgroundColor=[UIColor whiteColor];
    backView.tag=299;
    if (view) {
        [view addSubview:backView];
    }else{
        [self.view addSubview:backView];
    }
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(8, (frame.size.height-50)/2, IPHONE_WIDTH-16, 50)];
    label.text=msg;
    label.numberOfLines=0;
    label.font=[UIFont systemFontOfSize:17];
    label.textColor=[UIColor lightGrayColor];
    label.textAlignment=NSTextAlignmentCenter;
    CGFloat height=[LZXHelper textHeightFromTextString:msg width:[label getView_Width] fontSize:15];
    [label changeView_Height:height+5];
    [backView addSubview:label];
    
    [backView bringSubviewToFront:self.view];
}

- (void)addRefreshViewWithFrame:(CGRect)frame msg:(NSString *)msg backView:(UIView *)view refreshMsg:(NSString *)refreshMsg{
    UIView *backView=(UIView*)[self.view viewWithTag:298];
    if (backView) {
        return;
    }
    backView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
    backView.backgroundColor=[UIColor whiteColor];
    backView.tag=298;
    if (view) {
        [view addSubview:backView];
    }else{
        [self.view addSubview:backView];
    }
    
    
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(8, (frame.size.height-50)/2, IPHONE_WIDTH-16, 50)];
    label.text=msg;
    label.numberOfLines=0;
    label.font=[UIFont systemFontOfSize:17];
    label.textColor=[UIColor lightGrayColor];
    label.textAlignment=NSTextAlignmentCenter;
    CGFloat height=[LZXHelper textHeightFromTextString:msg width:[label getView_Width] fontSize:15];
    [label changeView_Height:height+5];
    
    UIButton *button=[MyControl creatButtonWithFrame:CGRectMake((IPHONE_WIDTH-150)/2, label.y+label.height+10, 150, 40) target:self sel:@selector(refreshButtonClick) tag:0 image:nil title:refreshMsg?refreshMsg:@"重试"];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.backgroundColor=COLOR_MIDBLUE;
    [backView addSubview:button];
    [backView addSubview:label];
    
    [backView bringSubviewToFront:self.view];
}

- (void)refreshButtonClick{
    
}

- (void)removeRefreshView{
    UIView *backView=(UIView*)[self.view viewWithTag:298];
    if (backView)
    {
        [backView removeFromSuperview];
        backView=nil;
    }
}

- (void)removeReminderView{
    UIView *backView=(UIView*)[self.view viewWithTag:299];
    if (backView)
    {
        [backView removeFromSuperview];
        backView=nil;
    }
}

#pragma mark -两个时间的比较
- (BOOL)compareOneTime:(NSString *)beginStr withAnotherTime:(NSString *)endStr
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    //    NSString *oneDayStr = [dateFormatter stringFromDate:oneDay];
    //    NSString *anotherDayStr = [dateFormatter stringFromDate:anotherDay];
    NSDate *dateA = [dateFormatter dateFromString:beginStr];
    NSDate *dateB = [dateFormatter dateFromString:endStr];
    NSComparisonResult resultB = [dateA compare:dateB];
    //NSOrderedAscending 大于
    //NSOrderedDescending 小于
    if (resultB==NSOrderedAscending) {
        //前者大
        return YES;
    }else{
        return NO;
    }
}

#pragma mark -与当前时间的比较
- (BOOL)compareTime:(NSString *)beginStr
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    //    NSString *oneDayStr = [dateFormatter stringFromDate:oneDay];
    //    NSString *anotherDayStr = [dateFormatter stringFromDate:anotherDay];
    NSDate *dateA = [dateFormatter dateFromString:beginStr];
    NSDate *dateNow=[NSDate date];
    NSComparisonResult resultA = [dateA compare:dateNow];
    //NSOrderedAscending 大于
    //NSOrderedDescending 小于
    if (resultA==NSOrderedAscending) {
        return YES;
    }else{
        return NO;
    }
}

- (BOOL)shouldAutorotate{
    //是否允许转屏
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    //viewController所支持的全部旋转方向
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    //viewController初始显示的方向
    return UIInterfaceOrientationPortrait;
}

#pragma mark 根据businesscode查找响应的状态
- (NSString *)getStatusLabelTextWithBusinessCode:(NSString *)businessCode isOwn:(NSString *)isOwn isOperate:(NSString *)isOperate state:(NSString *)state{
    // isOwn1是0否
    // isOperate是否可以操作0不能1可以
    if ([businessCode isEqualToString:@"GC0009"]) {
        if ([state isEqualToString:@"0"]) {
            if ([isOwn isEqualToString:@"0"]) {
                if ([isOperate isEqualToString:@"0"]) {
                    return @"已审批";
                } else if ([isOperate isEqualToString:@"1"]) {
                    return @"待审批";
                }
            } else if ([isOwn isEqualToString:@"1"]) {
                return @"待审批";
            } else {
                return [@"isOwn有误" stringByAppendingString:isOwn];
            }
        } else if ([state isEqualToString:@"1"]) {
            if ([isOwn isEqualToString:@"0"]) {
                if ([isOperate isEqualToString:@"0"]) {
                    return @"已审批";
                } else if ([isOperate isEqualToString:@"1"]) {
                    return @"待审批";
                }
            } else if ([isOwn isEqualToString:@"1"]) {
                return @"待审批";
            } else {
                return [@"isOwn有误" stringByAppendingString:isOwn];
            }
        } else if ([state isEqualToString:@"2"]) {
            return @"审批驳回";
        } else if ([state isEqualToString:@"3"]) {
            return @"待汇报";
        } else if ([state isEqualToString:@"4"]) {
            return @"汇报驳回";
        } else if ([state isEqualToString:@"5"]) {
            if ([isOwn isEqualToString:@"0"]) {
                if ([isOperate isEqualToString:@"0"]) {
                    return @"已审核";
                } else if ([isOperate isEqualToString:@"1"]) {
                    return @"待审核";
                }
            } else if ([isOwn isEqualToString:@"1"]) {
                return @"待审核";
            } else {
                return [@"isOwn有误" stringByAppendingString:isOwn];
            }
        } else if ([state isEqualToString:@"6"]) {
            return @"审核通过";
        } else {
            return [@"state有误" stringByAppendingString:state];
        }
    } else if ([businessCode isEqualToString:@"YC0012"]
               || [businessCode isEqualToString:@"JB0011"]) {
        
        if ([state isEqualToString:@"0"]) {
            if ([isOwn isEqualToString:@"0"]) {
                if ([isOperate isEqualToString:@"0"]) {
                    return @"已审核";
                } else if ([isOperate isEqualToString:@"1"]) {
                    return @"待审批";
                }
            } else if ([isOwn isEqualToString:@"1"]) {
                return @"待审批";
            } else {
                return [@"isOwn有误" stringByAppendingString:isOwn];
            }
        } else if ([state isEqualToString:@"1"]) {
            if ([isOwn isEqualToString:@"0"]) {
                if ([isOperate isEqualToString:@"0"]) {
                    return @"已审批";
                } else if ([isOperate isEqualToString:@"1"]) {
                    return @"待审批";
                }
            } else if ([isOwn isEqualToString:@"1"]) {
                return @"待审批";
            } else {
                return [@"isOwn有误" stringByAppendingString:isOwn];
            }
        } else if ([state isEqualToString:@"2"]) {
            return @"审批驳回";
        } else if ([state isEqualToString:@"3"]) {
            return @"审批通过";
        } else {
            return [@"state有误" stringByAppendingString:state];
        }
    } else {
        if ([state isEqualToString:@"0"]) {
            return @"草稿";
        } else if ([state isEqualToString:@"1"]) {
            if ([isOwn isEqualToString:@"0"]) {
                if ([isOperate isEqualToString:@"0"]) {
                    return @"已审批";
                } else if ([isOperate isEqualToString:@"1"]) {
                    return @"待审批";
                }
            } else if ([isOwn isEqualToString:@"1"]) {
                return @"待审批";
            } else {
                return [@"isOwn有误" stringByAppendingString:isOwn];
            }
        } else if ([state isEqualToString:@"2"]) {
            return @"审批驳回";
        } else if ([state isEqualToString:@"3"]) {
            return @"待销假";
        } else if ([state isEqualToString:@"4"]) {
            return @"销假驳回";
        } else if ([state isEqualToString:@"5"]) {
            if ([isOwn isEqualToString:@"0"]) {
                if ([isOperate isEqualToString:@"0"]) {
                    return @"已核销";
                } else if ([isOperate isEqualToString:@"1"]) {
                    return @"待核销";
                }
            } else if ([isOwn isEqualToString:@"1"]) {
                return @"待核销";
            } else {
                return [@"isOwn有误" stringByAppendingString:isOwn];
            }
        } else if ([state isEqualToString:@"6"]) {
            return @"已核销";
        } else {
            return [@"state有误" stringByAppendingString:state];
        }
    }
    return @"";
}

//获取业务类型
- (NSString *)getVacateTypeWithBusinessCode:(NSString *)businessCode sex:(NSString *)sex{
    if ([businessCode isEqualToString:@"BJ0001"]) {
        return @"病假";
    } else if ([businessCode isEqualToString:@"SJ0002"]) {
        return @"事假";
    } else if ([businessCode isEqualToString:@"NJ0003"]) {
        return @"年假";
    } else if ([businessCode isEqualToString:@"CJ0004"]) {
        if ([sex isEqualToString:@"0"]) {
            return @"护理假";
        } else if ([sex isEqualToString:@"1"]) {
            return @"产假";
        } else {
            return sex;
        }
    } else if ([businessCode isEqualToString:@"HJ0005"]) {
        return @"婚假";
    } else if ([businessCode isEqualToString:@"SJ0006"]) {
        return @"丧假";
    } else if ([businessCode isEqualToString:@"TQ0007"]) {
        return @"探亲假";
    } else if ([businessCode isEqualToString:@"GS0008"]) {
        return @"工伤假";
    } else if ([businessCode isEqualToString:@"TX0010"]) {
        return @"调休";
    } else if ([businessCode isEqualToString:@"GC0009"]) {
        return @"公出";
    } else if ([businessCode isEqualToString:@"YC0012"]) {
        return @"异常打卡申请";
    } else if ([businessCode isEqualToString:@"JB0011"]) {
        return @"加班";
    } else if ([businessCode isEqualToString:@"KQ0013"]) {
        return @"考勤业务";
    } else {
        return @"";
    }

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
